package cc.angis.xiugallery.provider;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;
import cc.angis.xiugallery.data.FolderData;
import cc.angis.xiugallery.db.FavouriteDBHelper;
import cc.angis.xiugallery.db.TableConstants;

public class FavouriteGalleryProvider implements IFolderSourceProvider{
	
	private Context context;
	
	private List<FolderData> folderDataList;
	
	public FavouriteGalleryProvider(Context context){
		this.context = context;
		folderDataList = new ArrayList<FolderData>();
	}

	@Override
	public int getSize() {
		return folderDataList.size();
	}

	@Override
	public void initSource() {
	    // Get the base URI for the People table in the Contacts content provider.
		FavouriteDBHelper dbHelper = new FavouriteDBHelper(context, TableConstants.TABLE_FAVOURITE);
		try{
			folderDataList = dbHelper.getAllFavs(); 
			folderDataList.add(folderDataList.size(), new FolderData("", "", -1));
		} catch(Exception e){
			
		} finally{
			dbHelper.closeDB();
		}
	}
	
	
	@Override
	public List<FolderData> getFolderList() {
		return folderDataList;		
	}

	@Override
	public Object getItem(int num) {
		// TODO Auto-generated method stub
		return folderDataList.get(num).getId();
	}

	@Override
	public int getType() {
		return 1;
	}

	@Override
	public void addFolderData(FolderData folderData) {
		folderDataList.add(0, folderData);
		
	}

	@Override
	public String getItemText(int num) {
		return folderDataList.get(num).getName();
	}

	@Override
	public Object getImageItem(int num) {
		if (folderDataList.get(num).getThumbnailList() != null && folderDataList.get(num).getThumbnailList().size() > 0)
			return folderDataList.get(num).getThumbnailList().get(0);
		else 
			return null;
	}

	@Override
	public void removeFolderData(int position) {
		folderDataList.remove(position);
	}
	
}
